﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO.Compression;
using System.IO;
using System.Threading;
using System.Configuration;

namespace BaccaratRally.Client
{
    public partial class FormSetting : Form
    {
        public FormSetting()
        {
            InitializeComponent();

            this.txbBaseSize.Text = CurrUser.UserSetting[0];
            this.txbSize1.Text = CurrUser.UserSetting[1];
            this.txbRate1.Text = CurrUser.UserSetting[2];
            this.txbSize2.Text = CurrUser.UserSetting[3];
            this.txbRate2.Text = CurrUser.UserSetting[4];
            this.txbXRate.Text = CurrUser.UserSetting[5];
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            CurrUser.UserSetting[0] = this.txbBaseSize.Text.Trim();
            CurrUser.UserSetting[1] = this.txbSize1.Text.Trim();
            CurrUser.UserSetting[2] = this.txbRate1.Text.Trim();
            CurrUser.UserSetting[3] = this.txbSize2.Text.Trim();
            CurrUser.UserSetting[4] = this.txbRate2.Text.Trim();
            CurrUser.UserSetting[5] = this.txbXRate.Text.Trim();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ServiceUrl"] + "Setting.aspx?UserName=" + CurrUser.UserName + "&Setting=" + CurrUser.UserSetting[0] + "," + CurrUser.UserSetting[1] + "," + CurrUser.UserSetting[2] + "," + CurrUser.UserSetting[3] + "," + CurrUser.UserSetting[4] + "," + CurrUser.UserSetting[5]);

            #region Build HttpRequest
            request.Method = "GET";
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate,sdch");
            request.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
            #endregion

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            String resultstring = "";

            if (response.ContentEncoding == "gzip")
            {
                Stream outStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress, true);
                StreamReader reader = new StreamReader(outStream, Encoding.GetEncoding("UTF-8"));
                resultstring = reader.ReadToEnd();
                reader.Close();
                outStream.Close();
            }
            else
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
                resultstring = reader.ReadToEnd();
                reader.Close();
            }

            this.Close();

        }
    }
}
